home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / cmdity / yk212src.lha / Yak_2.12_Src / Prefs / Filereq.c < prev    next >
C/C++ Source or Header  |  1995-11-16  |  3KB  |  126 lines

  1.  
  2.  
  3. #include <exec/types.h>
  4. #include <exec/memory.h>
  5. #include <intuition/intuition.h>
  6. #include <libraries/asl.h>
  7. #include <proto/dos.h>
  8. #include <proto/exec.h>
  9. #include <proto/intuition.h>
  10. #include <proto/gadtools.h>
  11. #include <proto/asl.h>
  12. #include <string.h>
  13.  
  14. #ifdef MUI        /* NMC */
  15. #include <libraries/mui.h>
  16. #include <proto/muimaster.h>
  17. #endif            /* NMC */
  18.  
  19. /* BGUI */
  20. #ifdef BGUI    /* NMC */
  21. #include <libraries/bgui.h>
  22. #include <libraries/bgui_macros.h>
  23. #include <proto/bgui.h>
  24. #endif
  25.  
  26. #include "code.h"
  27. #include "filereq.h"
  28.  
  29.  
  30.  
  31. #ifdef GADTOOLS
  32. /* Handle window IDCMP's */
  33. STACKARGS static struct IntuiMessage *
  34. RequesterHook(ULONG mask,
  35.               struct IntuiMessage *msg,
  36.               void *dummy)
  37. {
  38.     if (mask == FRF_INTUIFUNC)
  39.     {
  40.         /* Only refresh events are executed */
  41.         if (msg->Class == IDCMP_REFRESHWINDOW)
  42.         {
  43.              struct Window *w=msg->IDCMPWindow;
  44.  
  45.              /* Execute GadTools refresh */
  46.              GT_BeginRefresh(w);
  47.              GT_EndRefresh(w,TRUE);
  48.         }
  49.  
  50.         /* Return pointer to original IntuiMessage */
  51.         return(msg);
  52.     }
  53.     return(0);
  54. }
  55. #endif    /* GADTOOLS */
  56.  
  57.  
  58.  
  59. /* Open a file requester */
  60. char *OpenFileRequester(FileReqParams *frp)
  61. {
  62.      struct Window *win=frp->frp_Window;
  63.      struct Screen *scr=win->WScreen;
  64.      char *oldfile, *filepart;
  65.      char *dirname=NULL;
  66.      char *newfile=NULL;
  67.      ULONG len;
  68.  
  69.      oldfile  = frp->frp_InitialFile;
  70.  
  71.      filepart = FilePart(oldfile);
  72.  
  73.      len = filepart-oldfile;
  74.  
  75.      if (dirname=AllocVec(len+1, MEMF_CLEAR))
  76.      {
  77.          struct FileRequester *filereq;
  78.  
  79.          if (len > 0)
  80.              strncpy(dirname, oldfile, len);
  81.  
  82.          dirname[len] = '\0';
  83.  
  84.          *PathPart(dirname) = '\0';
  85.  
  86.          /* Allocate File Requester */
  87.          if (filereq=AllocAslRequestTags(ASL_FileRequest, TAG_DONE));
  88.          {
  89.              /* Show requester */
  90.              if (AslRequestTags(filereq,
  91.                                 ASLFR_Window,          win,
  92.                                 ASLFR_InitialLeftEdge, win->LeftEdge,
  93.                                 ASLFR_InitialTopEdge,  win->TopEdge+scr->WBorTop+scr->RastPort.TxHeight+1,
  94.                                 ASLFR_TitleText,       frp->frp_Title,
  95.                                 ASLFR_Flags1,          FRF_INTUIFUNC | frp->frp_Flag1,
  96.                                 ASLFR_Flags2,          FRF_REJECTICONS,
  97. #ifdef GADTOOLS
  98.                                 ASLFR_HookFunc,        RequesterHook,
  99. #endif
  100.                                 ASLFR_InitialDrawer,   dirname,
  101.                                 ASLFR_InitialFile,     filepart,
  102.                                 TAG_DONE))
  103.              {
  104.                  /* File name valid ? */
  105.                  if (len=strlen(filereq->fr_File))
  106.                  {
  107.                      if (filereq->fr_Drawer)
  108.                          len += strlen(filereq->fr_Drawer)+1;
  109.  
  110.                      if (newfile=AllocVec(len+1, MEMF_CLEAR))
  111.                      {
  112.                          if (filereq->fr_Drawer)
  113.                              strcpy(newfile, filereq->fr_Drawer);
  114.                          AddPart(newfile, filereq->fr_File, len+1);
  115.                      }
  116.                  }
  117.              }
  118.              FreeAslRequest(filereq);
  119.          }
  120.          FreeVec(dirname);
  121.      }
  122.  
  123.      /* return new file name */
  124.      return(newfile);
  125. }
  126.